package com.example.concurrency.xx.thread;

/**
 * @author: dangwen
 * @createDate: 2021/2/3
 */
public class ThreadDemo extends Thread{
    @Override
    public void run() {
        System.out.println(Thread.currentThread().getName()+"--0--"+isInterrupted());
        while (!isInterrupted()){
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                e.printStackTrace();
                // 异常会重新将true改为false
                System.out.println(Thread.currentThread().getName()+"--1--"+isInterrupted());
//                interrupt();

            }
            System.out.println("11111111111");
        }
        System.out.println(Thread.currentThread().getName()+"--2--"+isInterrupted());
    }

    public static void main(String[] args) {
        ThreadDemo t = new ThreadDemo();
        t.start();
        try {
            Thread.sleep(10);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        t.interrupt();
    }
}
